package ch6_pointer

import (
	"errors"
	"fmt"
)

var InsufficientFundsError = errors.New("cannot withdraw, insufficient funds")

type Bitcoin int

func (b Bitcoin) String() string {
	return fmt.Sprintf("%d BTC", b)
}

type Wallet struct {
	bitcoin Bitcoin
}

func (w *Wallet) Deposit(amount Bitcoin) {
	w.bitcoin += amount
}

func (w *Wallet) Balance() Bitcoin {
	return w.bitcoin
}

func (w *Wallet) Withdraw(amt Bitcoin) error {
	if amt > w.bitcoin {
		return InsufficientFundsError
	}
	w.bitcoin -= amt
	return nil
}
